#pragma once
#include <iostream>
#include <jsoncpp/json/json.h>

class Protocol;
class ProtocolLoginReq;
class ProtocolRegisterReq;
class ProtocolCommonResp;

using ProtocolPtr = std::shared_ptr<Protocol>;
using ProtocolLoginReqPtr = std::shared_ptr<ProtocolLoginReq>;
using ProtocolRegisterReqPtr = std::shared_ptr<ProtocolRegisterReq>;
using ProtocolCommonRespPtr = std::shared_ptr<ProtocolCommonResp>;

class Protocol
{
public:
    enum Type
    {
        UnKnown = 0,
        CommonResp,
        LoginReq,
        RegisterReq,
        Max,

    };

    Protocol(Type type)
        : _type(type)
    {
    }

    virtual std::string serialize() = 0;
    virtual void deserialize(const Json::Value&) = 0;

    static bool isValidProtocolType(int value)
    {
        constexpr int min = (int)(Protocol::Type::UnKnown);
        constexpr int max = (int)(Protocol::Type::Max);
        return value > min && value < max;
    }

    Protocol::Type getType()
    {
        return _type;
    }

    virtual ~Protocol() {}

    Type _type;
};




